package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/28
 * @Description:
 */
@RestController
@RequestMapping("tag")
public class TagController {


    @Autowired
    private TagService tagService;

    @GetMapping
    public List<Tag> getList() {
        return tagService.list();
    }

    @DeleteMapping("{id}")
    public Boolean deleteById(@PathVariable("id") Integer id) {
        boolean b = tagService.removeById(id);
        return b;
    }

    @PostMapping
    public Tag add(@RequestBody Tag tag) {
        tag.setCreatedate(new Date());
        boolean save = tagService.save(tag);
        return tag;
    }


    @GetMapping("{id}")
    public Tag getById(@PathVariable("id") Integer id) {
        return  tagService.getById(id);
    }


}
